package com.gale.park.modules.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gale.park.modules.ums.mapper.UmsAdminRoleRelationMapper;
import com.gale.park.modules.ums.model.UmsAdminRoleRelation;
import com.gale.park.modules.ums.service.UmsAdminRoleRelationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 管理员角色关系管理Service实现类
 * Created by macro on 2020/8/21.
 */
@Service
public class UmsAdminRoleRelationServiceImpl extends ServiceImpl<UmsAdminRoleRelationMapper, UmsAdminRoleRelation> implements UmsAdminRoleRelationService {
    @Override
    public Boolean findRole(Long adminId) {

        QueryWrapper<UmsAdminRoleRelation> queryWrapper = new QueryWrapper<>();

        queryWrapper.lambda()
                .eq(UmsAdminRoleRelation::getAdminId, adminId)
                .eq(UmsAdminRoleRelation::getRoleId, 5);

        UmsAdminRoleRelation umsAdminRoleRelation = baseMapper.selectOne(queryWrapper);

        return umsAdminRoleRelation == null;
    }

    @Override
    public boolean add(Long id, Long roleId) {
        UmsAdminRoleRelation adminRoleRelation = new UmsAdminRoleRelation();

        adminRoleRelation.setAdminId(id);
        adminRoleRelation.setRoleId(roleId);

        return this.baseMapper.insert(adminRoleRelation) > 0;
    }
}
